//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class EffectContainer : Effect, IOfficeXmlSerializableAs
    {
        private List<Effect> effects = new List<Effect>();

        private string name;

        private EffectContainerType type;

        public List<Effect> Effects
        {
            get { return effects; }
            set { effects = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public EffectContainerType Type
        {
            get { return type; }
            set { type = value; }
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("cont"))
            {
                Name = c.GetOptionalString("name");
                Type = c.GetOptionalEnum("type", EffectContainerType.Sibling);
                Effect e = ReadEffect(c);
                while (e != null)
                {
                    Effects.Add(e);
                    e = ReadEffect(c);
                }
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("cont"))
            {
                c.SetOptionalString("name", Name);
                c.SetOptionalEnum("type", Type, EffectContainerType.Sibling);
                foreach (Effect e in Effects)
                    c.WriteElement(e);
            }
        }

        void IOfficeXmlSerializableAs.ReadXmlAs(string name, ReadContext context)
        {
            using (var c = context.Read(name))
            {
                Name = c.GetOptionalString("name");
                Type = c.GetOptionalEnum("type", EffectContainerType.Sibling);
                Effect e = ReadEffect(c);
                while (e != null)
                {
                    Effects.Add(e);
                    e = ReadEffect(c);
                }
            }
        }

        void IOfficeXmlSerializableAs.WriteXmlAs(string name, WriteContext context)
        {
            using (WriteContext c = context.Write(name))
            {
                c.SetOptionalString("name", Name);
                c.SetOptionalEnum("type", Type, EffectContainerType.Sibling);
                foreach (Effect e in Effects)
                    c.WriteElement(e);
            }
        }
    }
}